﻿using System;
using SharpObjects.Data.EntityMapping;

namespace Authorization
{
    public class AccessControlEntry
    {
        public enum eAccessSpecifier
        {
            GrantAccess = 0,
            DenyAccess = 1
        }

        [Mapping("resource_id")]
        public int ResourceId { get; set; }

        [Mapping("accessor_name")]
        public string AccessorName { get; set; }

        [Mapping("deny_access")]
        public bool DenyAccess { get; set; }

        public eAccessSpecifier AccessSpecifier
        {
            get
            {
                if(this.DenyAccess)
                {
                    return eAccessSpecifier.DenyAccess;
                }
                else
                {
                    return  eAccessSpecifier.GrantAccess;
                }
            }
            set
            {
                if(value == eAccessSpecifier.DenyAccess)
                {
                    this.DenyAccess = true;
                }
                else
                {
                    this.DenyAccess = false;
                }
            }
        }
        
        [Mapping("created_date")]
        public DateTime CreatedDate { get; set; }

        [Mapping("modified_date")]
        public DateTime? ModifiedDate { get; set; }
    }
}